import json

import requests

data = {
    'pageNo': 1,
    'pageSize': 65,
    'bondType': 100001,
    'issueYear': 2023
}
url = 'https://iftp.chinamoney.com.cn/ags/ms/cm-u-bond-md/BondMarketInfoListEN'
req = requests.post(url, data=data)
res_data = json.loads(req.text)
result_list = res_data["data"]["resultList"]
row = []
with open('qs1.csv', 'w') as f:
    title = 'ISIN, Bond Code, Issuer, Bond Type, Issue Date, Latest Rating\n'
    f.write(title)
for result_data in result_list:
    row_data = result_data["isin"] + ',' + result_data["bondCode"] + ',' + result_data["entyFullName"] + ',' \
          + result_data["bondType"] + ',' + result_data["issueEndDate"] + ',' + result_data["debtRtng"] + "\n"
    row.append(row_data)
    with open('qs1.csv', 'a') as f:
        f.write(row_data)
